package com.wechet.Handler;

import com.wechet.VO.ResultVo;
import com.wechet.exception.AuthException;
import com.wechet.exception.SellException;
import com.wechet.utils.ResultVoUtil;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by sc on 2017/9/29.
 * 拦截登录异常
 */


@ControllerAdvice
public class SellerExceptionHandler {

    @ExceptionHandler(value = AuthException.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public ModelAndView handlerAuthException() {

        return new ModelAndView("/index/index");
    }

    @ExceptionHandler(value = SellException.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public ResultVo handleSellException(SellException e) {
        return ResultVoUtil.error(e.getCode(), e.getMessage());
    }
}
